package com.crm.system.controller.orderManager;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.customerManager.CustomerProductDetailMemberCard;
import com.crm.model.qo.customerManager.BackMoneyQO;
import com.crm.system.service.orderManager.CustomerProductOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @ Author ：pym
 * @ Date   ：2021/3/12 10:38
 */
@RestController
@RequestMapping("/loginFree")
@Slf4j
public class LoginFreeController {
    @Autowired
    CustomerProductOrderService customerProductOrderService;

    /**
     * 财务-销总-退款详情
     * @Author bj
     * @Date  2021/7/27 9:27
     */
    @PostMapping("/xzCustomerOrderBackMoneyDetail")
    public DataResponse xzCustomerOrderBackMoneyDetail(HttpServletRequest request,
                                                     @RequestParam(value="orderBackMoneyId",required = false) String orderBackMoneyId,  //退款表主键
                                                     @RequestParam(value="productOrderId",required = false) String productOrderId //订单id
    ){
        try{
            Map<String,Object> map = customerProductOrderService.xzCustomerOrderBackMoneyDetail(orderBackMoneyId,productOrderId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),map);
        }catch(Exception e){
            log.error("loginFree customerOrderBackMoneyDetail error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 销总审核退款(财务端)
     * @Author bj
     * @Date  2021/7/27 9:27
     * @param backMoneyQO -退款产品信息
     */
    @PostMapping("/xzOrderRefundFinance")
    public DataResponse xzOrderRefundFinance(@RequestBody BackMoneyQO backMoneyQO){
        try{
            Boolean result = customerProductOrderService.xzOrderRefundFinance(backMoneyQO);
            if (result) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("loginFree xzOrderRefundFinance error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 财务-销总-余额退款详情
     * @Author bj
     * @Date  2021/7/27 9:27
     */
    @PostMapping("/xzBalanceBackMoneyDetail")
    public DataResponse xzBalanceBackMoneyDetail(HttpServletRequest request,
                                                       @RequestParam(value="orderBackMoneyId",required = false) String orderBackMoneyId  //退款表主键
    ){
        try{
            Map<String,Object> map = customerProductOrderService.xzBalanceBackMoneyDetail(orderBackMoneyId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),map);
        }catch(Exception e){
            log.error("loginFree xzBalanceBackMoneyDetail error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 销总余额审核退款(财务端)
     * @Author bj
     * @Date  2021/7/27 9:27
     * @param backMoneyQO -退款产品信息
     */
    @PostMapping("/xzBalanceRefundFinance")
    public DataResponse xzBalanceRefundFinance(@RequestBody BackMoneyQO backMoneyQO){
        try{
            Boolean result = customerProductOrderService.xzBalanceRefundFinance(backMoneyQO);
            if (result) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("loginFree xzBalanceRefundFinance error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 修改会员卡的起始时间和结束时间
     * @Author bj
     * @Date  2021/7/27 9:27
     */
    @PostMapping("/updateDate")
    public DataResponse updateDate(@RequestParam(value="startTm",required = false) String startTm,
                                   @RequestParam(value="endTm",required = false) String endTm,
                                   @RequestParam(value="memberCardNumber",required = false) String memberCardNumber){
        try{
            Boolean result = customerProductOrderService.updateDate(startTm,endTm,memberCardNumber);
            if (result) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("loginFree xzBalanceRefundFinance error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 补卡
     * @Author bj
     * @Date  2021/7/27 9:27
     */
    @PostMapping("/repairHairpin")
    public DataResponse repairHairpin(@RequestParam(value="reqParam",required = false) String reqParam){
        try{
            Boolean result = customerProductOrderService.repairHairpin(reqParam);
            if (result) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("loginFree repairHairpin error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }




}
